//
//  HDMacro.h
//  AccountEasy
//
//  Created by mac on 2020/7/22.
//  Copyright © 2020 AccountEasy. All rights reserved.
//

#ifndef HDMacro_h
#define HDMacro_h

#pragma mark - 服务器地址和端口号

#define kIsTestServer 1

//
#if (kIsTestServer == 0)//测试环境
#define kServerHost             @"http://192.168.111.166"
#define kServerPort             @""

#elif (kIsTestServer == 1)//正式环境 ⚠️ kIsTestServer == 1 用于判断正式服是否开启云打印
#define kServerHost             @"https://retail.fuyungroup.com"
#define kServerPort             @""

#elif (kIsTestServer == 2)//测试环境2
#define kServerHost             @"http://192.168.0.155"
#define kServerPort             @"9081"

#elif (kIsTestServer == 3)//支付环境
#define kServerHost             @"http://192.168.0.156"
#define kServerPort             @"9091"

#elif (kIsTestServer == 4)//支付环境
#define kServerHost             @"http://192.168.101.155"
#define kServerPort             @"9091"

#elif (kIsTestServer == 5)//外网穿透，访问内网155服务器
#define kServerHost             @"https://6784390fh.zicp.fun"
//#define kServerPort             @""
#define kServerPort             @"443"

#elif (kIsTestServer == 6)//自动选择
#define kServerHost             [[NSUserDefaults standardUserDefaults] valueForKey:@"ServerHost"]
#define kServerPort             [[NSUserDefaults standardUserDefaults] valueForKey:@"ServerPort"]

#endif

#define SA_BASE_URL(url)  [NSString stringWithFormat:@"%@:%@/%@",kServerHost,kServerPort,url]

#pragma mark - NSLog
#ifdef DEBUG
#define HMString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent

#define HDLog(...) printf("%s 第%d行: %s\n\n", [HMString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);
#else
#define HDLog(...)
#endif

#pragma mark - App常用颜色
#define kColor(R, G, B, A) [UIColor colorWithRed:(R)/255.f green:(G)/255.f blue:(B)/255.f alpha:(A)]
#define kRedColor           kColor(255, 114, 131, 1)
#define kGrayColor          kColor(100, 100, 100, 1.f)
#define kLightgGrayColor    kColor(150, 150, 150, 1.f)
#define kYellowColor        kColor(255, 201, 95, 1.f)
#define kGreenColor         kColor(59, 179, 76, 1.f)
#define kBuleColor          kColor(116, 133, 244, 1.f)
#define kLineColor          kColor(240, 240, 240, 1.f)
#define kBlackColor         kColor(68, 68, 68, 1.f)
#define kOrangeColor        kColor(255, 98, 48, 1.f)
#define kLightgOrangeColor  kColor(255, 186, 73, 1.f)
#define kBgColor            kColor(240, 240, 240, 1.f)
#define kPinkColor          kColor(254, 84, 161, 1.f)

#define kTextBgColor        kColor(236, 238, 242, 1)
#define kTextColor          kColor(160, 163, 189, 1)

#pragma mark - 文字颜色
#define kGlobalTextColorPourpre kColor(150,14,90,1.0)        //!< 文字绛紫色
#define kGlobalTextColorLightGray kColor(200,200,200,1.0)    //!< 文字浅灰色

#pragma mark - 屏幕设置信息
#define kBaseScreenHeight 667.f                            //!<基准高度
#define kBaseScreenWidth  375.f                            //!<基准宽度
#define kScreenBounds   [UIScreen mainScreen].bounds       //!<屏幕bounds
#define kScreenWidth    kScreenBounds.size.width            //!<屏幕宽度
#define kScreenHeight   kScreenBounds.size.height           //!<屏幕高度
#define kScreenScale    (kScreenWidth / kBaseScreenWidth)   //!<屏幕比例
#define kScaleNum(num)  kScreenScale * (num)                  //!<按屏幕比例变化数字
#define kEdgeInsetsMake(top_,left_,buttom_,right_)     UIEdgeInsetsMake((top_)*kScreenScale,(left_)*kScreenScale,(buttom_)*kScreenScale,(right_)*kScreenScale) //!<内缩适配


#pragma mark - Masonry
#define kMasLeft(num)       make.left.equalTo(@(kScaleNum(num)))
#define kMasRight(num)      make.right.equalTo(@(kScaleNum(num)))
#define kMasTop(num)        make.top.equalTo(@(kScaleNum(num)))
#define kMasBottom(num)     make.bottom.equalTo(@(kScaleNum(num)))
#define kMasWidth(num)      make.width.equalTo(@(kScaleNum(num)))
#define kMasHeight(num)     make.height.equalTo(@(kScaleNum(num)))

#pragma mark - 字体
#define kBigYoungFontName    @"BigYoungMediumGB2.0"
#define kBMHarryFontName     @"BM harry"

#define kFontWithName(name, size_) \
[UIFont fontWithName:name size:(size_)*kScreenScale]

#define kBFont(size_)    [UIFont boldSystemFontOfSize:(size_)*kScreenScale]

#define kFont(size_)     [UIFont fontWithName:@"Helvetica" size:(size_)*kScreenScale]

#define kLabelSize(text,font)  [text boundingRectWithSize:CGSizeMake(kScreenWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size          //!<计算label宽高

#pragma mark - 版本
#define kCurrentDeviceSystem [UIDevice currentDevice].systemVersion.floatValue
#define KIsiPhoneX ((kStatusBarHeight >= 44)?YES:NO)

#pragma mark - 第三方 聊天 依赖
#define WeakSelf __weak typeof(self) weakSelf = self;
#define kStatusBarHeight [UIApplication sharedApplication].statusBarFrame.size.height
#define QM_IS_IPHONEX ((kStatusBarHeight == 44)?YES:NO)
#define kMainCellColor [UIColor colorWithRed:248/255.0 green:248/255.0 blue:255/255.0 alpha:1]
#define kInputViewHeight 50

#pragma mark - 设备信息
#define kUserDefault  [NSUserDefaults standardUserDefaults]
#define KTimestamp    getCurStringFromDate(@"YYYYMMddHHmmss")
#define KMerchantId   [HDLoginManger shareInStance].loginModel.merchantId

#define kDeviceIdKey        @"SA_DeviceId"
#define kDeviceId           [kUserDefault valueForKey:kDeviceIdKey]
#define kLoginNameKey       @"SA_LoginName"
#define kLoginName          [kUserDefault valueForKey:kLoginNameKey]
#define kPasswordKey        @"SA_Password"
#define kPassword           [kUserDefault valueForKey:kPasswordKey]
#define kUserTypeKey        @"SA_UserType"
#define kUserType           [kUserDefault valueForKey:kUserTypeKey]
#define kExperienceKey      @"SA_ExperienceKey"
#define kExperience         [kUserDefault valueForKey:kExperienceKey]
#define kPrintKey           @"SA_kPrint"
#define kPrint              [kUserDefault valueForKey:kPrintKey]
#define kReViewKey          @"SA_ReView"
#define kReView             [kUserDefault valueForKey:kReViewKey]
#define kEyeKey             @"SA_Eye"
#define kEye                [kUserDefault valueForKey:kEyeKey]
#define kSelectPswKey       @"SA_SelectPswKey"
#define kSelectPsw          [kUserDefault valueForKey:kSelectPswKey]
#define kAotuLoginKey       @"SA_AotuLoginKey"
#define kAotuLogin          [kUserDefault valueForKey:kAotuLoginKey]
#define kDeviceTokenKey     @"SA_DeviceToken"
#define kDeviceToken        [kUserDefault valueForKey:kDeviceTokenKey]

#define kTipVersionIntKey   @"SA_TipVersionIntKey"
#define kTipVersionInt      [kUserDefault valueForKey:kTipVersionIntKey]

#define kRegisteredOpenPaymentKey   @"SA_RegisteredOpenPayment"
#define kRegisteredOpenPayment      [kUserDefault valueForKey:kRegisteredOpenPaymentKey]

#define kPrintOpenKey        @"SA_PrintOpenKey"
#define kPrintOpen           [kUserDefault valueForKey:kPrintOpenKey]

#define kPrintTypeKey        @"SA_PrintTypeKey"
#define kPrintType           [kUserDefault valueForKey:kPrintTypeKey]

#define kPrintLeftKey        @"SA_kPrintLeftKey"
#define kPrintLeft           [kUserDefault valueForKey:kPrintLeftKey]

#define kPrintTopKey         @"SA_kPrintTopKey"
#define kPrintTop            [kUserDefault valueForKey:kPrintTopKey]

#define kPrintDirectionKey   @"SA_kPrintDirectionKey"
#define kPrintDirection      [kUserDefault valueForKey:kPrintDirectionKey]

/************************************用户信息相关*********************************************/

///用户登录
#define URL_USER_LOGIN  @"/login"

///用户注册
#define URL_USER_RESIST @"/merchant/register"

///获取验证码
#define URL_LOGIN_GET_CODE  @"/merchant/sendCode"

///获取校验码
#define URL_LOGIN_GET_IMG_CODE  @"/merchant/getImgCode"

///修改密码
#define URL_USER_PASSWORD  @"/getPassword"

/*****************************************************************************************/

/***********************************商品信息相关**********************************************/

#define URL_PRODUCT_LIST  @"/product/list"
#define URL_PRODUCT_BATCHUPPERORLOWER  @"/product/batchUpperOrLower"
#define URL_PRODUCT_DETAIL  @"/product/detail"
#define URL_PRODUCT_ADD  @"product/add"
#define URL_PRODUCT_UPDATE  @"/product/update"
#define URL_PRODUCT_SPECSATTR_TOCHECK  @"/product/specsAttr/toCheck"
#define URL_PRODUCT_SPECSATTR_LIST  @"/product/specsAttr/list"
#define URL_PRODUCT_SPECSATTR_DEL  @"/product/specsAttr/del"
#define URL_PRODUCT_SPECSATTR_ADD  @"/product/specsAttr/add"
#define URL_PRODUCT_UNIT_ADD  @"/unit/add"
#define URL_PRODUCT_ATTR_ADD  @"/attr/add"
#define URL_PRODUCT_UNIT_LIST  @"/unit/list"
#define URL_PRODUCT_ATTR_LIST  @"/attr/list"
#define URL_PRODUCT_UNIT_DELETE  @"/unit/delete"
#define URL_PRODUCT_ATTR_DELETE  @"/attr/delete"
#define URL_PRODUCT_UPLOAD  @"/common/uploadPics"
#define URL_PRODUCT_GETCONDITION  @"/product/getAppConditionV2"
#define URL_PROVIDER_LIST  @"/provider/list"
#define URL_PRODUCT_BATCHPRICET  @"/product/batchPrice"
#define URL_PRODUCT_BATCHSTOCK  @"/product/batchStock"

/*****************************************************************************************/

/***********************************往来账目相关**********************************************/

#define URL_ACCOUNT_CUSTOMER_UPDATE  @"/account/customer/update"
#define URL_ACCOUNT_CUSTOMER_LIST  @"/account/customer/list"
#define URL_ACCOUNT_CUSTOMER_SEARCH  @"/account/customer/search"
#define URL_ACCOUNT_CUSTOMER_SAVE  @"/account/customer/save"
#define URL_ACCOUNT_CUSTOMER_GETCONDITION  @"/account/customer/getCondition"
#define URL_ACCOUNT_PROVIDER_LIST  @"/provider/list"
#define URL_ACCOUNT_PROVIDER_ADD  @"/provider/add"
#define URL_ACCOUNT_PROVIDER_UPDATE  @"/provider/update"
#define URL_ACCOUNT_ACCOUNT_LIST  @"/provider/account/list"
#define URL_ACCOUNT_PROVIDER_DETAIL  @"/provider/account/detail"
/*****************************************************************************************/

/***********************************系统设置相关**********************************************/

#define URL_SYSTEM_EMP_LIST  @"/system/emp/list"
#define URL_SYSTEM_STORE_DETAIL  @"/system/store/detail"
#define URL_SYSTEM_COMMON_UPLOAD  @"/common/upload"
#define URL_SYSTEM_EMP_UPDATE  @"/system/emp/update"
#define URL_SYSTEM_EMP_SAVE  @"/system/emp/save"
#define URL_SYSTEM_STORE_UPDATE @"/system/store/update"
#define URL_SYSTEM_SITE_DETAIL @"/system/site/detail"
#define URL_SYSTEM_EMP_SEARCH @"/system/emp/search"
#define URL_SETTINGS_LIST @"/system/settings/list"

/*****************************************************************************************/

/***********************************销售开单相关**********************************************/

#define URL_SALES_FLAT_LIST  @"/sales/flat/list"
#define URL_SALES_FLAT_DETAIL  @"/sales/flat/detail"
#define URL_SALES_WAREHOUSE_PURCHASE_FINDPRODUCT  @"/warehouse/purchase/findProduct"
#define URL_SALES_PEND_LIST  @"/sales/pend/list"
#define URL_SALES_PEND_DETAIL  @"/sales/pend/detail"
#define URL_SALES_PEND_SAVE  @"/sales/pend/save"
#define URL_SALES_SAVE  @"/sales/save"
#define URL_SALES_PRODUCTLIST  @"/sales/productList"
#define URL_SALES_INVOICE_LIST @"/sales/invoice/list"
#define URL_SALES_INVOICE_DETAIL @"/sales/invoice/detail"
#define URL_SALES_INVOICE_REMOVE @"/sales/invoice/remove"
#define URL_SALES_LIST @"/sales/list"
#define URL_STOCK_FLOW_GETCONDITION @"/stock/flow/getCondition"
#define URL_STOCK_DETAIL_LIST  @"/stock/detail/list"
#define URL_SALES_PRINT  @"/sales/print"

#define URL_SALES_MANYPRODUCTLIST  @"/sales/manyProductList"
/*****************************************************************************************/

/***********************************商品入库相关**********************************************/


#define URL_WAREHOUSE_PEND_LIST  @"/warehouse/pend/list"
#define URL_WAREHOUSE_PEND_DETAIL  @"/warehouse/pend/detail"
#define URL_WAREHOUSE_FLAT_LIST  @"/warehouse/flat/list"
#define URL_WAREHOUSE_FLAT_DETAIL  @"/warehouse/flat/detail"
#define URL_WAREHOUSE_PEND_SAVE  @"/warehouse/pend/save"
#define URL_WAREHOUSE_PURCHASE_SAVE  @"/warehouse/purchase/save"
#define URL_WAREHOUSE_PURCHASE_INVOICE_LIST @"/warehouse/purchase/invoice/list"
#define URL_WAREHOUSE_PURCHASE_INVOICE_DETAIL @"/warehouse/purchase/invoice/detail"
#define URL_WAREHOUSE_PURCHASE_INVOICE_REMOVE @"/warehouse/purchase/invoice/remove"
#define URL_WAREHOUSE_PURCHASE_DETAIL_GETTYPE @"/warehouse/purchase/detail/getType"
#define URL_WAREHOUSE_PURCHASE_DETAIL_LIST @"/warehouse/purchase/detail/list"


/***********************************库存管理相关**********************************************/

#define URL_STOCK_PREVIEW_LIST  @"/stock/preview/list"
#define URL_STOCK_PREVIEW_LISTV2  @"/stock/preview/listV2"
#define URL_STOCK_FLOW_LIST  @"/stock/flow/list"
#define URL_PREVIEW_EARLYLIST  @"/stock/preview/earlyWarningList"
#define URL_PREVIEW_DETAIL  @"/stock/preview/detail"
#define URL_PREVIEW_UPDATESTOCK  @"/stock/preview/updateStock"


/***********************************辅助计算**********************************************/
CG_INLINE UIColor *colorHex(NSInteger rgbValue) {
    return [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0
                           green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0
                            blue:((float)(rgbValue & 0xFF)) / 255.0
                           alpha:1.0];
}

CG_INLINE UIColor *colorHexA(NSInteger rgbValue, CGFloat alpha) {
   return [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0
                          green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0
                           blue:((float)(rgbValue & 0xFF)) / 255.0
                          alpha:alpha];
}

//去除空格
CG_INLINE NSString *trimString(NSString *string) {
        NSString *text = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        return text;
}

//判空
CG_INLINE NSString *emptyString(NSString *string) {
    if (string && string.length > 0) {
        return string;
    }
    return @"";
}

//辅助计算
#define DEFAULT_DATE_EN_TEMPLATE_STRING @"yyyy.MM.dd"
CG_INLINE NSString *getStringFromDate(NSString *dateStringTemplate, NSDate *date) {
    [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    if (!dateStringTemplate) { dateStringTemplate = DEFAULT_DATE_EN_TEMPLATE_STRING; }

    [dateFormatter setDateFormat:dateStringTemplate];
    NSString *dateStr = [dateFormatter stringFromDate:date];

    return dateStr;
}
CG_INLINE NSString *getCurStringFromDate(NSString *dateStringTemplate) {
    
    NSDate * date = [NSDate date];
    return getStringFromDate(dateStringTemplate, date);
}
CG_INLINE NSString* timeToMouth(NSString*strtime){
    NSArray *list = [strtime componentsSeparatedByString:@"-"];
    NSString *str = strtime;
    if(list.count>=2){
        str = [NSString stringWithFormat:@"%@年%@月",list[0],list[1]];
    }
    return str;
}

#endif /* HDMacro_h */
